const http = require('http')
const url = require('url')

http.createServer(async (req, res) => {
  let urlStr = req.url
  let { pathname } = url.parse(urlStr)

  res.writeHead(200, {
    'content-type': 'application/json',
    'Access-Control-Allow-Origin': '*'
  })

  switch(pathname) {
    case '/api/list':
      res.write(JSON.stringify({x: 0}))
      break
  }
  res.end()
}).listen(8081, () => {
  console.log('localhost:8081')
})